package com.itheima.d7_threadpool2;

import java.util.concurrent.*;

public class ExecutorServiceDemo2 {
    public static void main(String[] args) {
        //创建线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                5,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy()
        );
        //创建MyCallable对象
        MyCallable m1 = new MyCallable(100);
        MyCallable m2 = new MyCallable(200);
        MyCallable m3 = new MyCallable(300);
        MyCallable m4 = new MyCallable(400);

        Future<String> f1 = pool.submit(m1);
        Future<String> f2 = pool.submit(m2);
        Future<String> f3 = pool.submit(m3);
        Future<String> f4 = pool.submit(m4);
        pool.shutdown();

        try {
            System.out.println(f1.get());
            System.out.println(f2.get());
            System.out.println(f3.get());
            System.out.println(f4.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
